#!/bin/bash

## name : start-ipfs-completenode.sh
## desc : 实现 IPFS 完备节点
## author: liqs
## update : 2020.6.9

int=0
nohup ipfs log tail >> log0.txt 2>&1 &

filename=log0.txt
filesize=0
maxsize=$((1024*2))

while (($int<2))
do

	pid=$(ps -aux | grep "ipfs log" | awk 'NR==1{print $2}')

	if [ $int == 0 ]
	then
		nohup ipfs log tail >> log1.txt 2>&1 &
	elif [ $int == 1 ]
	then
		nohup ipfs log tail >> log0.txt 2>&1 &
	fi

	while (($filesize<$maxsize))
	do
		filesize=`ls -l $filename | awk '{ print $5 }'`
		sleep 2
	done

	kill $pid

	java -classpath ipfs-completenode-1.0.0-jar-with-dependencies.jar com.supermap.Main $filename $1

	if [ $int == 0 ]
	then
		int=1
		filename=log1.txt
		filesize=0
	elif [ $int == 1 ]
	then
		int=0
		filename=log0.txt
		filesize=0
	fi

done




